package cn.dzhang.rcp.hyperbola;

import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.IFontProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.model.IWorkbenchAdapter;
import org.eclipse.ui.model.IWorkbenchAdapter2;

import cn.dzhang.rcp.hyperbola.common.ResourceManager;
import cn.dzhang.rcp.hyperbola.common.UIUtils;

public class HyperbolaLabelProvider extends LabelProvider implements
		IColorProvider, IFontProvider {
	@Override
	public String getText(Object element) {
		IWorkbenchAdapter adapter = UIUtils.getAdapter(element);
		return adapter == null ? super.getText(element) : adapter
				.getLabel(element);
	}

	@Override
	public Image getImage(Object element) {
		IWorkbenchAdapter adapter = UIUtils.getAdapter(element);

		return adapter == null ? super.getImage(element) : ResourceManager
				.getImage(adapter.getImageDescriptor(element));
	}

	@Override
	public Color getForeground(Object element) {
		IWorkbenchAdapter2 adapter2 = UIUtils.getAdapter2(element);
		return adapter2 == null ? null : ResourceManager.getColor(adapter2
				.getForeground(element));
	}

	@Override
	public Color getBackground(Object element) {
		IWorkbenchAdapter2 adapter2 = UIUtils.getAdapter2(element);
		return adapter2 == null ? null : ResourceManager.getColor(adapter2
				.getBackground(element));
	}

	@Override
	public Font getFont(Object element) {
		IWorkbenchAdapter2 adapter2 = UIUtils.getAdapter2(element);
		return adapter2 == null ? null : ResourceManager.getFont(adapter2
				.getFont(element));
	}
}
